using TMPro;
using UnityEngine;

namespace CardGameObject.CollectScene
{
    public class CollectDeckCard : MonoBehaviour
    {
        private CollectManager collectManager;

        public TextMeshProUGUI NameText;
        public TextMeshProUGUI CountText;

        private long CardId { get; set; }

        public string CardName { get; set; }

        private int CardCount { get; set; }

        private void Start()
        {
            collectManager = CollectManager.GetInstance();
        }
        
        public void OnClick()
        {
            CardCount -= 1;
            CountText.text = CardCount.ToString();
            // 从卡组中删除该卡牌
            collectManager.RemoveCardFromDeck(CardId,gameObject);
            if(CardCount <= 0)
            {
                Destroy(gameObject);
            }
            // 修改展示的卡牌中剩余的数量
            if (collectManager.CollectCardList.ContainsKey(CardId))
            {
                CollectCard card = collectManager.CollectCardList[CardId].GetComponent<CollectCard>();
                card.CardCount += 1;
                card.CountText.text = card.CardCount.ToString();
            }
        }

    

        public void SetCardInfo(long cardId, string cardName , int cardCount)
        {
            CardId = cardId;
            CardName = cardName;
            CardCount = cardCount;

            NameText.text = cardName;
            CountText.text = CardCount.ToString();
        }

        public void AddCount()
        {
            CardCount += 1;
            CountText.text = CardCount.ToString();
        }

        internal void ReduceCount()
        {
            CardCount -= 1;
            CountText.text = CardCount.ToString();
        }
    }
}
